<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * 登录管理
 * @author lxn
 */
class Login extends CI_Controller
{
	private static $data = array();
	public function __construct()
	{
		parent::__construct();		
		$this->load->model('Admin_model','admin_model');
	}

	/**
	 * 登录
	 * @author yxl
	 * 2015-5-20 18:37:11
	 * */
	public function index()
	{  		
		$this->load->view('admin/login.html',self::$data);

	}
	
	
	/**
	 * 登录表单提交
	 * @author yxl
	 * 2015-5-20 19:35:50
	 */
	public function Login()
	{
	    
		$adminName = trim($this->input->post('adminName'));
		$password = trim($this->input->post('password'));
		$adminData = $this->admin_model->getAdminByName($adminName, $password);

		if (empty($adminData))//用户名密码错误
		{
		    show400('用户名或密码错误');
		}else{
		    $this->session->set_userdata('adminId',$adminData['adminId']);
		    show200([],'登录成功');
		}
	}

	

	/**
	 * 退出系统
	 * */
	public function logout()
	{
	    $this->session->sess_destroy();
	    redirect('admin/login');
	}


	/**
	 * 生成验证码
	 */
	public function captcha()
	{	   
		$this->load->model('Vcode_model','vcode');
		$this->vcode->doimg();
		$this->session->unset_userdata(array('cap'=>''));
		$this->session->set_userdata(array('cap'=>md5(strtolower($this->vcode->getCode()))));
		die;
	}
}
/* End of file Login.php */